<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.js"></script>
  <script>
    const mixin = { // 定义了混入
      data() {
        return {
          msg: '公共混入中的数据'
        }
      },
      methods: {
        changeMsg() {
          this.msg = "数据改变了"
        }
      },
      computed: {
        reverseMsg() {
          return this.msg.split('').reverse().join('')
        }
      }
    }
    Vue.component('CommonHead', {
      template: `
        <div>
          <h1 ref="h1">我是头部组件</h1>
          {{ msg }}
          {{ reverseMsg }}
          <button @click="changeMsg">改变msg</button>
        </div>
      `,
      data(){
        return {
          msg:'我是组件的msg'
        }
      },
      mixins: [mixin]
    })
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>

</html>